/*
 * Copyright (c) 2015-2999 广州朗尊软件科技有限公司<www.legendshop.cn> All rights reserved.
 *
 * https://www.legendshop.cn/
 *
 * 版权所有,并保留所有权利
 *
 */
package com.sankuai.inf.leaf.segment.model;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author legendshop
 */
public class Segment {
	private AtomicLong value = new AtomicLong(0);
	private volatile long max;
	private volatile int step;
	private SegmentBuffer buffer;

	public Segment(SegmentBuffer buffer) {
		this.buffer = buffer;
	}

	public AtomicLong getValue() {
		return value;
	}

	public void setValue(AtomicLong value) {
		this.value = value;
	}

	public long getMax() {
		return max;
	}

	public void setMax(long max) {
		this.max = max;
	}

	public int getStep() {
		return step;
	}

	public void setStep(int step) {
		this.step = step;
	}

	public SegmentBuffer getBuffer() {
		return buffer;
	}

	public long getIdle() {
		return this.getMax() - getValue().get();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("Segment(");
		sb.append("value:");
		sb.append(value);
		sb.append(",max:");
		sb.append(max);
		sb.append(",step:");
		sb.append(step);
		sb.append(")");
		return sb.toString();
	}
}
